<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>创建权限</title> $!{include("import_js_css.html")}
</head>
<body>
	$!{include("header.html")}
	<div class="menu_all">
		<div class="div_search_result clear">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">创建权限</h3>
			</div>
			<div class="panel-form-add">
				<form class="form-horizontal" role="form" action="yueyogaAdmin/addAuthority.jhtml" method="POST">
					<div class="panel-form-layout">
						<label for="txtName" class="col-sm-1 control-label">名称</label>
						<div class="col-sm-3">
							<input type="text" required class="form-control" name="name" id="name" value="">
						</div>
						<label for="selStatus" class="col-sm-1 control-label">是否启用</label>
						<div class="col-sm-3">
							<select class="selectpicker show-menu-arrow" data-width="100%" name="enabled" id="enabled">
								<option value="1">是</option>
								<option value="2">否</option>
							</select>
						</div>
						<br /> <br /> <label for="txtRemarks" class="col-sm-1 control-label">描述</label>
						<div class="col-sm-3">
							<textarea class="form-control panel-form-address" name="description" id="description"></textarea>
						</div>
						<br> <br> <br>
						<br>
						<div class="panel-btn-search">
							<button id="btnSave" type="button" class="btn btn-default btn-ade-default panel-mr">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	function documentReady() {
		$("#btnSave").click(function() {
			var flag = false;
			var name = $("#name").val();
			
			$.ajax({
				type	: "post",
				url 	: "yueyogaAdmin/checkAuthorityName.jhtml",
				async	: false,
				data	: {"name": name},
				success	: function(response) {
					var res = eval("(" + response + ")");
					if (res.success) {
						flag = false;
					} else {
						flag = true;
						alert(res.msg);
					}
				}
			});
			
			if(flag) return;
			
			var enabled = $("#enabled").select2("val");
			var description = $("#description").val();
			var url = "yueyogaAdmin/addAuthority.jhtml";
			$.post(url, {
				name : name,
				enabled : enabled,
				description : description
			}, function(resp) {
				var data = eval('(' + resp + ')');
				if(data.success){
					var d = alert(data.msg);
					setTimeout(function(){
						d.close().remove();
						window.location.href = "yueyogaAdmin/findAllAuthorities.jhtml";
					},1000);
				}else{
					error(resp.msg);
				}
			});
		});

		
		$("#enabled").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
	}
</script>
</html>
